package cn.tedu.egmvc2.controller;

import cn.tedu.egmvc2.mapper.AddressMapper;
import cn.tedu.egmvc2.pojo.entity.Address;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/address/")
public class AddressController {
    @Autowired(required = false)
    private AddressMapper addressMapper;
    //添加收货地址
    @RequestMapping("insert")
    public String insert(Address address) {
        addressMapper.insertAddress(address);
        return "添加成功";
    }

    //查询收货地址
    @RequestMapping("select")
    public List<Address> select(String username) {
        List<Address> addressList = addressMapper.selectAddress();
        return addressList;
    }

    //除收货地址
    @RequestMapping("delete")
    public String delete(int id) {
        addressMapper.deleteAddress(id);
        return "删除成功";
    }

    //修改收货地址
    @RequestMapping("update")
    public String update(Address address) {
        addressMapper.updateAddress(address);
        return "修改成功";
    }
}
